package com.huawei.hianalytics.ab.cd.bc;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.Pair;
import com.huawei.hianalytics.ab.bc.bc.ab;
import com.huawei.hianalytics.ab.bc.kl.bc;
import com.huawei.hwCloudJs.d.d;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.lang.reflect.InvocationTargetException;

public class cd extends ab {
    public static String bc() {
        String str;
        String str2 = "";
        try {
            str = (String) Class.forName("com.huawei.android.os.BuildEx").getMethod("getUDID", new Class[0]).invoke(null, new Object[0]);
            try {
                com.huawei.hianalytics.ab.bc.ef.ab.bc("hmsSdk", "getUDID success");
            } catch (ClassNotFoundException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed");
                return str;
            } catch (AndroidRuntimeException e2) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID getudid failed, RuntimeException is AndroidRuntimeException");
                return str;
            } catch (NoSuchMethodException e3) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : NoSuchMethodException");
                return str;
            } catch (IllegalAccessException e4) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : Illegal AccessException");
                return str;
            } catch (IllegalArgumentException e5) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : Illegal ArgumentException");
                return str;
            } catch (InvocationTargetException e6) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : InvocationTargetException");
                return str;
            }
        } catch (ClassNotFoundException e7) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed");
            return str;
        } catch (AndroidRuntimeException e8) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID getudid failed, RuntimeException is AndroidRuntimeException");
            return str;
        } catch (NoSuchMethodException e9) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : NoSuchMethodException");
            return str;
        } catch (IllegalAccessException e10) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : Illegal AccessException");
            return str;
        } catch (IllegalArgumentException e11) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : Illegal ArgumentException");
            return str;
        } catch (InvocationTargetException e12) {
            str = str2;
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getUDID method invoke failed : InvocationTargetException");
            return str;
        }
        return str;
    }

    @SuppressLint({"HardwareIds", "MissingPermission"})
    public static String ef(Context context) {
        String str = "";
        if (bc.ab(context, "android.permission.READ_PHONE_STATE")) {
            return str;
        }
        String deviceId;
        try {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
            if (telephonyManager != null) {
                deviceId = telephonyManager.getDeviceId();
                return deviceId;
            }
        } catch (SecurityException e) {
            com.huawei.hianalytics.ab.bc.ef.ab.de("hmsSdk", "getDeviceID Incorrect permissions!");
        }
        deviceId = str;
        return deviceId;
    }

    public static String fg(Context context) {
        String str = Build.SERIAL;
        return (TextUtils.isEmpty(str) || str.equalsIgnoreCase(d.b)) ? hi(context) : str;
    }

    public static Pair<String, String> gh(Context context) {
        if (bc.ab(context, "android.permission.READ_PHONE_STATE")) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getMccAndMnc() Pair value is empty");
            return new Pair("", "");
        }
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
        if (telephonyManager == null) {
            return new Pair("", "");
        }
        if (telephonyManager.getSimState() != 5) {
            return new Pair("", "");
        }
        String networkOperator = telephonyManager.getNetworkOperator();
        return (TextUtils.isEmpty(networkOperator) || TextUtils.equals(networkOperator, HwAccountConstants.NULL)) ? new Pair("", "") : networkOperator.length() > 3 ? new Pair(networkOperator.substring(0, 3), networkOperator.substring(3)) : new Pair("", "");
    }

    private static String hi(Context context) {
        com.huawei.hianalytics.ab.bc.ef.ab.ab("hmsSdk", "getSerial : is executed.");
        String str = "";
        if (context == null || bc.ab(context, "android.permission.READ_PHONE_STATE")) {
            return str;
        }
        try {
            return VERSION.SDK_INT >= 26 ? Build.getSerial() : str;
        } catch (SecurityException e) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("hmsSdk", "getSerial() Incorrect permissions!");
            return "";
        }
    }
}
